import socket, struct, sys
from binascii import hexlify
from errno import EINPROGRESS

try:
    from micropython import const
    from time import ticks_ms, ticks_diff
    import uasyncio as asyncio

    async def open_connection(addr, ssl):
        """
        open_connection
        """
        ...

    try:
        from machine import unique_id
        import network

        STA_IF = ...
    except:
        from unix_fix import *

    def is_awaitable(f):
        """
        is_awaitable
        """
        ...
except:
    from cpy_fix import *

try:
    import logging

    log = ...
except:
    class Logger:
        def debug(self, msg, *args):
            """
            debug
            """
            ...

        def info(self, msg, *args):
            """
            info
            """
            ...

        def warning(self, msg, *args):
            """
            warning
            """
            ...

    log = ...

_CONN_DELAY = ...

CONN_CLOSED = ...
CONN_TIMEOUT = ...
PROTO_ERROR = ...
CONN_ERRS = ...

config = ...

def set_last_will(config, topic, message, retain=False, qos=0):
    """
    set_last_will
    """
    ...

def _qos_check(qos):
    """
    _qos_check
    """
    ...

class MQTTMessage:
    def __init__(self, topic, message, retain=False, qos=0, pid=None):
        """
        init
        """
        ...

class MQTTProto:
    def __init__(self, subs_cb, puback_cb, suback_cb, pingresp_cb, sock_cb=None):
        """
        init
        """
        ...

    async def connect(self, addr, client_id, clean, user=None, pwd=None, ssl=None, keepalive=0, lw=None):
        """
        connect
        """
        ...

    async def _as_read(self, n):
        """
        _as_read
        """
        ...

    async def _as_write(self, bytes_wr, drain=True):
        """
        _as_write
        """
        ...

    async def _send_str(self, s, drain=True):
        """
        _send_str
        """
        ...

    async def _read_varint(self):
        """
        _read_varint
        """
        ...

    def _write_varint(self, array, index, value):
        """
        _write_varint
        """
        ...

    async def ping(self):
        """
        ping
        """
        ...

    async def disconnect(self):
        """
        disconnect
        """
        ...

    def isconnected(self):
        """
        isconnected
        """
        ...

    async def publish(self, msg, dup=0):
        """
        publish
        """
        ...

    async def subscribe(self, topic, qos, pid):
        """
        subscribe
        """
        ...

    async def read_msg(self):
        """
        read_msg
        """
        ...

PING_PID = ...

class MQTTClient:
    def __init__(self, conf):
        """
        init
        """
        ...

    async def wifi_connect(self):
        """
        wifi_connect
        """
        ...

    def _dns_lookup(self):
        """
        _dns_lookup
        """
        ...

    async def connect(self):
        """
        connect
        """
        ...

    async def disconnect(self):
        """
        disconnect
        """
        ...

    def start(self):
        """
        start
        """
        ...

    def _newpid(self):
        """
        _newpid
        """
        ...

    def _got_puback(self, pid):
        """
        _got_puback
        """
        ...

    def _got_pingresp(self):
        """
        _got_pingresp
        """
        ...

    def _got_suback(self, pid, actual_qos):
        """
        _got_suback
        """
        ...

    async def _await_pid(self, pid):
        """
        _await_pid
        """
        ...

    async def _handle_msgs(self, proto):
        """
        _handle_msgs
        """
        ...

    async def _ping_n_wait(self, proto):
        """
        _ping_n_wait
        """
        ...

    async def _keep_alive(self, proto):
        """
        _keep_alive
        """
        ...

    async def _reconnect(self, proto, why, detail="n/a"):
        """
        _reconnect
        """
        ...

    async def _keep_connected(self):
        """
        _keep_connected
        """
        ...

    async def subscribe(self, topic, qos=0):
        """
        subscribe
        """
        ...

    async def publish(self, topic, msg, retain=False, qos=0, sync=True):
        """
        publish
        """
        ...
